package com.quanyan.stadium.web.api;

import com.quanyan.api.APIResponse;
import com.quanyan.stadium.api.req.*;
import com.quanyan.stadium.service.RadarChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created with IntelliJ IDEA.
 * User: zyq
 * Date: 2016/6/21 0021
 * Time: 22:02
 */


@RestController
@RequestMapping("/api/stadium/radarchart")
public class RadarChartController {

    @Autowired
    RadarChartService radarChartService;


    /**
     * 评价用户能力用户列表
     * @param request
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "commitUserList", method = RequestMethod.POST)
    public APIResponse commitUserList(@Valid @RequestBody ReqCommitUser request,
        BindingResult bindingResult,HttpServletRequest servletRequest) {
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(bindingResult.getAllErrors().toString());
        }
        if (request.getUid() == null) {
            request.setUid((Integer) servletRequest.getAttribute("uid"));
        }
        return radarChartService.commitUserList(request);
    }


    /**
     * 查询用户雷达能力图
     * @param request
     * @param bindingResult
     * @param servletRequest
     * @return
     */
    @RequestMapping(value = "userRadarChart", method = RequestMethod.POST)
    public APIResponse userRaderChart(@Valid @RequestBody ReqUserRadarChart request,
        BindingResult bindingResult, HttpServletRequest servletRequest) {
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(bindingResult.getAllErrors().toString());
        }
        if (request.getUid() == null) {
            request.setUid((Integer) servletRequest.getAttribute("uid"));
        }
        return APIResponse.returnSuccess(radarChartService.userRadarChart(request));
    }

    /**
     * 批量查询用户能力雷达图
     * @param request
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "userRadarChartBatch", method = RequestMethod.POST)
    public APIResponse userRadarChartBatch(@Valid @RequestBody ReqUserRadarChartBatch request,
        BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(bindingResult.getAllErrors().toString());
        }
        return APIResponse.returnSuccess(radarChartService.queryUserRadarChartBatch(request));
    }
    /**
     * 评价个人能力
     *
     * @param request
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "selfEvaluate", method = RequestMethod.POST)
    public APIResponse selfEvaluate(@Valid @RequestBody ReqRadarSelfEvaluate request, BindingResult bindingResult,HttpServletRequest servletRequest) {
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(bindingResult.getAllErrors().toString());
        }
        request.setUid((Integer) servletRequest.getAttribute("uid"));
        return radarChartService.selfEvaluate(request);
    }

    /**
     * 评价比赛
     *
     * @param request
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "evaluateGame", method = RequestMethod.POST)
    public APIResponse evaluateGame(@Valid @RequestBody ReqEvaluateGame request,
        BindingResult bindingResult,HttpServletRequest servletRequest) {
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(bindingResult.getAllErrors().toString());
        }
        request.setUid((Integer) servletRequest.getAttribute("uid"));
        return radarChartService.commitUserRadarChart(request);
    }

    @RequestMapping(value = "evaluateLevel", method = RequestMethod.POST)
    public APIResponse evaluateLevel(@Valid @RequestBody ReqUserRadarChart request,BindingResult bindingResult){
            if (bindingResult.hasErrors()) {
                return APIResponse.returnFail(bindingResult.getAllErrors().toString());
            }
        return radarChartService.evaluationLevel(request);
    }

    /**
     * 初始化评价系数
     *
     * @param request
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "initEvaluate", method = RequestMethod.POST)
    public APIResponse initEvaluate(@Valid @RequestBody ReqInitEvaluate request,
        BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(bindingResult.getAllErrors().toString());
        }

        return radarChartService.initEvaluation(request);
    }

    /**
     * 判断用户是否有雷达图数据
     *
     * @param request
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "checkRadarData", method = RequestMethod.POST)
    public APIResponse checkRadarData(@Valid @RequestBody ReqUserRadarChart request,
        BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(bindingResult.getAllErrors().toString());
        }
        return radarChartService.checkRadarData(request);
    }



}
